$(document).ready(function () {

    $("#header").load("Nav.html #Nav", function () {
        element.init();
        $("#CreditCard").addClass("layui-this");
    });
    laydate.render({
        elem: '#test1' //指定元素
        , format: 'yyyy-MM-dd'
    });
    laydate.render({
        elem: '#test2' //指定元素
        , format: 'yyyy-MM-dd'
    });
    $.get("/ShenBlue/imp/Bank_Catalog_Json", function (data) {
        console.log(data);
        const size = data.length;
        let i = 0;
        for (; i < size; i++) {
            const item = data[i];
            $("#Bank").append("<option value=\"" + item.id + "\">" + item.name + "</option>");
        }
        form.render('select');
    });
});
table.on('tool(test)', function (obj) {
    var data = obj.data; //获得当前行数据
    var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
    console.log(data);
    if (layEvent === 'Modify') {
        Modify_CreditCard(data.card_id);
    } else if (layEvent === 'del') {
        Del_CreditCard(data.card_id);
    }
});

function Del_CreditCard(card_num) {
    layer.confirm('请确认是否删除', {
        btn: ['是', '否'] //按钮
    }, function () {
        $.post("/ShenBlue/imp/CreditCardInc", {mode: 3, card_id: card_num}, function (data) {
            const error = data["error"];
            const msg = data["msg"];
            if (error !== undefined) {
                layer.msg(error, {icon: 5});
                setTimeout("location.reload()", 1500);
                return;
            }
            layer.msg(msg, {icon: 1});
            setTimeout("location.reload()", 1500);
            return;
        });
    });
}

function Modify_CreditCard(card_num) {
    window.open('/ShenBlue/userInfoService/changeCreditCard.html?id=' + card_num);
}

function Reader_Select() {
    const card_id = IsEmpty($("#card_id").val()) ? "" : $("#card_id").val();
    const time_start = IsEmpty($("#test1").val()) ? "" : $("#test1").val();
    const time_end = IsEmpty($("#test2").val()) ? "" : $("#test2").val();
    const Bank_id = IsEmpty($("#Bank option:selected").val()) ? "" : $("#Bank option:selected").val();
    console.log(card_id);
    table.reload('test', {
        method: 'post'
        , url: '/ShenBlue/imp/CeaditCard_Service_Json'
        , where: {card_id: card_id, time_start: time_start, time_end: time_end, bank_id: Bank_id}
        , page: true
    });
}
